package org.jsping.loginservlet;

import java.io.IOException;
import java.net.URLEncoder;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.jsping.util.AuthUtil;

/**
 * 处理qq用户登陆的请求
 * 把qq登录的请求转发给qcallBack.do
 */
@WebServlet("/QQLogin")
public class QQLogin extends HttpServlet {
	private static final long serialVersionUID = 1L;
    
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String backUrl ="http://ping.xn--fiqs8s/QQcallBack.do";
		//通过工具类的qqappid来处理请求
		String url = "https://graph.qq.com/oauth2.0/authorize?"
				+ "response_type=code&"
				+ "client_id="+AuthUtil.QQAPPID
				+ "&redirect_uri="+URLEncoder.encode(backUrl)
				+ "&state=test";
		response.sendRedirect(url);
	}
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
